package vpfarm.master;

import java.io.IOException;

import jtools.ai.agenten.AMessage;
import jtools.ai.agenten.CycleBehavior;
import vpfarm.Constants;
import vpfarm.data.Status;

public class StatusBehavior extends CycleBehavior {
	
	private Master master;

	public StatusBehavior(Master master){
		this.master = master;
	}
	@Override
	public void execute() {
		AMessage msg = reciveMessage(true);
		if (msg.getSubject() == Constants.ASK_FOR_STATUS){
			try {
				Status status = new Status(this.master.frames, this.master.jobInfo, this.master.jobList, this.master.getLatestImage());
				AMessage rep = msg.createReplay(Constants.SEND_STATUS);
				rep.setContent(status);
				myAgent.sendMessage(rep);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else
			pushBack(msg);
	}

	@Override
	public void onEnd() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onStart() {
		// TODO Auto-generated method stub

	}

}
